﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace MassPokerTool.Infrastructure.Ocr
{
    public static class PokerstarsChatTextEvaluator
    {
        private static readonly object SyncRoot;
        private static readonly Queue<string> AlreadyProcessedTexts;

        static PokerstarsChatTextEvaluator()
        {
            SyncRoot = new object();
            AlreadyProcessedTexts = new Queue<string>(5);
        }

        public static IList<string> Evaluate(string inputText)
        {
            var splittedTexts = Regex.Split(inputText, "(Dealer)|(Administrator)");
            var newTexts = new List<string>();
            if (splittedTexts.Length > 1) // diese Bedigung soll entfernt werden
            {
                for (int i = 0; i < splittedTexts.Length; i++)
                {
                    if (splittedTexts[i] == "Dealer")
                    {
                        lock (SyncRoot)
                        {
                            ++i;
                            if (AlreadyProcessedTexts.Contains(splittedTexts[i]))
                                continue;
                            AlreadyProcessedTexts.Enqueue(splittedTexts[i]);
                            newTexts.Add("Dealer" + splittedTexts[i].Trim());
                        }
                    }
                    else if (splittedTexts[i] == "Administrator")
                        ++i;
                }
            }
            return newTexts;
        }
    }
}
